﻿using Freebase4net.Interfaces;
using Freebase4net.Operators.Bases;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Freebase4net.Operators
{
    public class OneOfOperator : OperatorBase, IOperator
    {
        private object[] _value;
        public OneOfOperator(object[] value)
            : base(value)
        {
            _value = value;
        }

        public string CreateJson(string key)
        {
            try
            {
                StringBuilder builder = new StringBuilder();
                var itemsInQuotes = _value
                    .Cast<string>()
                    .Select(x => string.Format("\"{0}\"", x));

                builder.AppendFormat("\"{0}|=\":[{1}]", key, string.Join(", ", itemsInQuotes));

                return builder.ToString();
            }
            catch (Exception e)
            {
                throw new OperatorArgumentException("string");
            }
        }
    }
}
